package iterators;

import IA.Menu;
import IA.MenuItem;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author Christopher
 */
public class MenuByPriceItr implements Iterator {
    List<MenuItem> menu;
    Double price;
    
    public MenuByPriceItr(List<MenuItem> menu, Double price){
        this.menu = menu;
        this.price = price;
    }
    
    @Override
    public boolean hasNext() {
        boolean isValid = false;
        while(!isValid && !menu.isEmpty()){
            if(menu.get(0).getCurrentPrice() < price){
                isValid = true;
            } else{
            menu.remove(0); 
            }
        }
        return isValid;
    }

    @Override
    public MenuItem next() {
        MenuItem item = menu.get(0);
        menu.remove(0);
        return item;
    }

    @Override
    public void remove() {
        menu.remove(0);
    }
    
}
